/**
 * 
 */
package com.weixinpay.controller.interfaced;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.Tools;
import com.weixinpay.config.WechatAccountConfig;

/**
 * @author zhanglingbing
 * @date 2018年5月3日
 */
@Controller
@RequestMapping(value = "/weixinpay")
public class WeixinPayController extends BaseController {

	/**
	 * 微信支付统一下单
	 * @author zhanglingbing
	 * @date 2018年5月3日
	 * @return
	 */
	@RequestMapping(value = "/unifiedorder")
	@ResponseBody
	public Object unifiedOrder() {
		logBefore(logger, "微信支付统一下单");
		Map<String, Object> map = new HashMap<String, Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		logBefore(logger, pd.toString());
		try {
			if (Tools.checkKey("UNIFIEDORDER", pd.getString("FKEY"))) { // 检验请求key值是否合法
				if (AppUtil.checkParam("unifiedOrder", pd)) { // 检查参数
					
					URL url = new URL("https://api.mch.weixin.qq.com/pay/unifiedorder");
					HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			        //请求方式
			        conn.setRequestMethod("POST");
					
					WechatAccountConfig we = new WechatAccountConfig();
					
					// 返回01为删除成功并返回
//					result = "01";
				} else {
					result = "03";
				}
			} else {
				result = "05";
			}
		} catch (Exception e) {
			logger.error(e.toString(), e);
		} finally {
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
}
